<?php


abstract class BasePost extends BaseObject  implements Persistent {


  const PEER = 'PostPeer';

	
	protected static $peer;

	
	protected $id;

	
	protected $user_id;

	
	protected $handle;

	
	protected $file;

	
	protected $datetime;

	
	protected $published;

	
	protected $comment_allow;

	
	protected $aUser;

	
	protected $collPostI18ns;

	
	private $lastPostI18nCriteria = null;

	
	protected $collPostTags;

	
	private $lastPostTagCriteria = null;

	
	protected $collComments;

	
	private $lastCommentCriteria = null;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

  
  protected $culture;

	
	public function __construct()
	{
		parent::__construct();
		$this->applyDefaultValues();
	}

	
	public function applyDefaultValues()
	{
		$this->user_id = 0;
		$this->handle = '';
		$this->published = 1;
		$this->comment_allow = 1;
	}

	
	public function getId()
	{
		return $this->id;
	}

	
	public function getUserId()
	{
		return $this->user_id;
	}

	
	public function getHandle()
	{
		return $this->handle;
	}

	
	public function getFile()
	{
		return $this->file;
	}

	
	public function getDatetime($format = 'Y-m-d H:i:s')
	{
		if ($this->datetime === null) {
			return null;
		}


		if ($this->datetime === '0000-00-00 00:00:00') {
									return null;
		} else {
			try {
				$dt = new DateTime($this->datetime);
			} catch (Exception $x) {
				throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->datetime, true), $x);
			}
		}

		if ($format === null) {
						return $dt;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $dt->format('U'));
		} else {
			return $dt->format($format);
		}
	}

	
	public function getPublished()
	{
		return $this->published;
	}

	
	public function getCommentAllow()
	{
		return $this->comment_allow;
	}

	
	public function setId($v)
	{
		if ($v !== null) {
			$v = (int) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = PostPeer::ID;
		}

		return $this;
	} 
	
	public function setUserId($v)
	{
		if ($v !== null) {
			$v = (int) $v;
		}

		if ($this->user_id !== $v || $v === 0) {
			$this->user_id = $v;
			$this->modifiedColumns[] = PostPeer::USER_ID;
		}

		if ($this->aUser !== null && $this->aUser->getId() !== $v) {
			$this->aUser = null;
		}

		return $this;
	} 
	
	public function setHandle($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->handle !== $v || $v === '') {
			$this->handle = $v;
			$this->modifiedColumns[] = PostPeer::HANDLE;
		}

		return $this;
	} 
	
	public function setFile($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->file !== $v) {
			$this->file = $v;
			$this->modifiedColumns[] = PostPeer::FILE;
		}

		return $this;
	} 
	
	public function setDatetime($v)
	{
						if ($v === null || $v === '') {
			$dt = null;
		} elseif ($v instanceof DateTime) {
			$dt = $v;
		} else {
									try {
				if (is_numeric($v)) { 					$dt = new DateTime('@'.$v, new DateTimeZone('UTC'));
															$dt->setTimeZone(new DateTimeZone(date_default_timezone_get()));
				} else {
					$dt = new DateTime($v);
				}
			} catch (Exception $x) {
				throw new PropelException('Error parsing date/time value: ' . var_export($v, true), $x);
			}
		}

		if ( $this->datetime !== null || $dt !== null ) {
			
			$currNorm = ($this->datetime !== null && $tmpDt = new DateTime($this->datetime)) ? $tmpDt->format('Y-m-d H:i:s') : null;
			$newNorm = ($dt !== null) ? $dt->format('Y-m-d H:i:s') : null;

			if ( ($currNorm !== $newNorm) 					)
			{
				$this->datetime = ($dt ? $dt->format('Y-m-d H:i:s') : null);
				$this->modifiedColumns[] = PostPeer::DATETIME;
			}
		} 
		return $this;
	} 
	
	public function setPublished($v)
	{
		if ($v !== null) {
			$v = (int) $v;
		}

		if ($this->published !== $v || $v === 1) {
			$this->published = $v;
			$this->modifiedColumns[] = PostPeer::PUBLISHED;
		}

		return $this;
	} 
	
	public function setCommentAllow($v)
	{
		if ($v !== null) {
			$v = (int) $v;
		}

		if ($this->comment_allow !== $v || $v === 1) {
			$this->comment_allow = $v;
			$this->modifiedColumns[] = PostPeer::COMMENT_ALLOW;
		}

		return $this;
	} 
	
	public function hasOnlyDefaultValues()
	{
						if (array_diff($this->modifiedColumns, array(PostPeer::USER_ID,PostPeer::HANDLE,PostPeer::PUBLISHED,PostPeer::COMMENT_ALLOW))) {
				return false;
			}

			if ($this->user_id !== 0) {
				return false;
			}

			if ($this->handle !== '') {
				return false;
			}

			if ($this->published !== 1) {
				return false;
			}

			if ($this->comment_allow !== 1) {
				return false;
			}

				return true;
	} 
	
	public function hydrate($row, $startcol = 0, $rehydrate = false)
	{
		try {

			$this->id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
			$this->user_id = ($row[$startcol + 1] !== null) ? (int) $row[$startcol + 1] : null;
			$this->handle = ($row[$startcol + 2] !== null) ? (string) $row[$startcol + 2] : null;
			$this->file = ($row[$startcol + 3] !== null) ? (string) $row[$startcol + 3] : null;
			$this->datetime = ($row[$startcol + 4] !== null) ? (string) $row[$startcol + 4] : null;
			$this->published = ($row[$startcol + 5] !== null) ? (int) $row[$startcol + 5] : null;
			$this->comment_allow = ($row[$startcol + 6] !== null) ? (int) $row[$startcol + 6] : null;
			$this->resetModified();

			$this->setNew(false);

			if ($rehydrate) {
				$this->ensureConsistency();
			}

						return $startcol + 7; 
		} catch (Exception $e) {
			throw new PropelException("Error populating Post object", $e);
		}
	}

	
	public function ensureConsistency()
	{

		if ($this->aUser !== null && $this->user_id !== $this->aUser->getId()) {
			$this->aUser = null;
		}
	} 
	
	public function reload($deep = false, PropelPDO $con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("Cannot reload a deleted object.");
		}

		if ($this->isNew()) {
			throw new PropelException("Cannot reload an unsaved object.");
		}

		if ($con === null) {
			$con = Propel::getConnection(PostPeer::DATABASE_NAME, Propel::CONNECTION_READ);
		}

				
		$stmt = PostPeer::doSelectStmt($this->buildPkeyCriteria(), $con);
		$row = $stmt->fetch(PDO::FETCH_NUM);
		$stmt->closeCursor();
		if (!$row) {
			throw new PropelException('Cannot find matching row in the database to reload object values.');
		}
		$this->hydrate($row, 0, true); 
		if ($deep) {  
			$this->aUser = null;
			$this->collPostI18ns = null;
			$this->lastPostI18nCriteria = null;

			$this->collPostTags = null;
			$this->lastPostTagCriteria = null;

			$this->collComments = null;
			$this->lastCommentCriteria = null;

		} 	}

	
	public function delete(PropelPDO $con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(PostPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}
		
		$con->beginTransaction();
		try {
			PostPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollBack();
			throw $e;
		}
	}

	
	public function save(PropelPDO $con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(PostPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}
		
		$con->beginTransaction();
		try {
			$affectedRows = $this->doSave($con);
			$con->commit();
			PostPeer::addInstanceToPool($this);
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollBack();
			throw $e;
		}
	}

	
	protected function doSave(PropelPDO $con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;

												
			if ($this->aUser !== null) {
				if ($this->aUser->isModified() || ($this->aUser->getCulture() && $this->aUser->getCurrentUserI18n()->isModified()) || $this->aUser->isNew()) {
					$affectedRows += $this->aUser->save($con);
				}
				$this->setUser($this->aUser);
			}

			if ($this->isNew() ) {
				$this->modifiedColumns[] = PostPeer::ID;
			}

						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = PostPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += PostPeer::doUpdate($this, $con);
				}

				$this->resetModified(); 			}

			if ($this->collPostI18ns !== null) {
				foreach ($this->collPostI18ns as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			if ($this->collPostTags !== null) {
				foreach ($this->collPostTags as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			if ($this->collComments !== null) {
				foreach ($this->collComments as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			$this->alreadyInSave = false;

		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


												
			if ($this->aUser !== null) {
				if (!$this->aUser->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aUser->getValidationFailures());
				}
			}


			if (($retval = PostPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}


				if ($this->collPostI18ns !== null) {
					foreach ($this->collPostI18ns as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}

				if ($this->collPostTags !== null) {
					foreach ($this->collPostTags as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}

				if ($this->collComments !== null) {
					foreach ($this->collComments as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}


			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = PostPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		$field = $this->getByPosition($pos);
		return $field;
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getId();
				break;
			case 1:
				return $this->getUserId();
				break;
			case 2:
				return $this->getHandle();
				break;
			case 3:
				return $this->getFile();
				break;
			case 4:
				return $this->getDatetime();
				break;
			case 5:
				return $this->getPublished();
				break;
			case 6:
				return $this->getCommentAllow();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true)
	{
		$keys = PostPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getUserId(),
			$keys[2] => $this->getHandle(),
			$keys[3] => $this->getFile(),
			$keys[4] => $this->getDatetime(),
			$keys[5] => $this->getPublished(),
			$keys[6] => $this->getCommentAllow(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = PostPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setId($value);
				break;
			case 1:
				$this->setUserId($value);
				break;
			case 2:
				$this->setHandle($value);
				break;
			case 3:
				$this->setFile($value);
				break;
			case 4:
				$this->setDatetime($value);
				break;
			case 5:
				$this->setPublished($value);
				break;
			case 6:
				$this->setCommentAllow($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = PostPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setUserId($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setHandle($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setFile($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setDatetime($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setPublished($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setCommentAllow($arr[$keys[6]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(PostPeer::DATABASE_NAME);

		if ($this->isColumnModified(PostPeer::ID)) $criteria->add(PostPeer::ID, $this->id);
		if ($this->isColumnModified(PostPeer::USER_ID)) $criteria->add(PostPeer::USER_ID, $this->user_id);
		if ($this->isColumnModified(PostPeer::HANDLE)) $criteria->add(PostPeer::HANDLE, $this->handle);
		if ($this->isColumnModified(PostPeer::FILE)) $criteria->add(PostPeer::FILE, $this->file);
		if ($this->isColumnModified(PostPeer::DATETIME)) $criteria->add(PostPeer::DATETIME, $this->datetime);
		if ($this->isColumnModified(PostPeer::PUBLISHED)) $criteria->add(PostPeer::PUBLISHED, $this->published);
		if ($this->isColumnModified(PostPeer::COMMENT_ALLOW)) $criteria->add(PostPeer::COMMENT_ALLOW, $this->comment_allow);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(PostPeer::DATABASE_NAME);

		$criteria->add(PostPeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setUserId($this->user_id);

		$copyObj->setHandle($this->handle);

		$copyObj->setFile($this->file);

		$copyObj->setDatetime($this->datetime);

		$copyObj->setPublished($this->published);

		$copyObj->setCommentAllow($this->comment_allow);


		if ($deepCopy) {
									$copyObj->setNew(false);

			foreach ($this->getPostI18ns() as $relObj) {
				if ($relObj !== $this) {  					$copyObj->addPostI18n($relObj->copy($deepCopy));
				}
			}

			foreach ($this->getPostTags() as $relObj) {
				if ($relObj !== $this) {  					$copyObj->addPostTag($relObj->copy($deepCopy));
				}
			}

			foreach ($this->getComments() as $relObj) {
				if ($relObj !== $this) {  					$copyObj->addComment($relObj->copy($deepCopy));
				}
			}

		} 

		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new PostPeer();
		}
		return self::$peer;
	}

	
	public function setUser(User $v = null)
	{
		if ($v === null) {
			$this->setUserId(0);
		} else {
			$this->setUserId($v->getId());
		}

		$this->aUser = $v;

						if ($v !== null) {
			$v->addPost($this);
		}

		return $this;
	}


	
	public function getUser(PropelPDO $con = null)
	{
		if ($this->aUser === null && ($this->user_id !== null)) {
			$c = new Criteria(UserPeer::DATABASE_NAME);
			$c->add(UserPeer::ID, $this->user_id);
			$this->aUser = UserPeer::doSelectOne($c, $con);
			
		}
		return $this->aUser;
	}

	
	public function clearPostI18ns()
	{
		$this->collPostI18ns = null; 	}

	
	public function initPostI18ns()
	{
		$this->collPostI18ns = array();
	}

	
	public function getPostI18ns($criteria = null, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(PostPeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collPostI18ns === null) {
			if ($this->isNew()) {
			   $this->collPostI18ns = array();
			} else {

				$criteria->add(PostI18nPeer::ID, $this->id);

				PostI18nPeer::addSelectColumns($criteria);
				$this->collPostI18ns = PostI18nPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(PostI18nPeer::ID, $this->id);

				PostI18nPeer::addSelectColumns($criteria);
				if (!isset($this->lastPostI18nCriteria) || !$this->lastPostI18nCriteria->equals($criteria)) {
					$this->collPostI18ns = PostI18nPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastPostI18nCriteria = $criteria;
		return $this->collPostI18ns;
	}

	
	public function countPostI18ns(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(PostPeer::DATABASE_NAME);
		} else {
			$criteria = clone $criteria;
		}

		if ($distinct) {
			$criteria->setDistinct();
		}

		$count = null;

		if ($this->collPostI18ns === null) {
			if ($this->isNew()) {
				$count = 0;
			} else {

				$criteria->add(PostI18nPeer::ID, $this->id);

				$count = PostI18nPeer::doCount($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(PostI18nPeer::ID, $this->id);

				if (!isset($this->lastPostI18nCriteria) || !$this->lastPostI18nCriteria->equals($criteria)) {
					$count = PostI18nPeer::doCount($criteria, $con);
				} else {
					$count = count($this->collPostI18ns);
				}
			} else {
				$count = count($this->collPostI18ns);
			}
		}
		$this->lastPostI18nCriteria = $criteria;
		return $count;
	}

	
	public function addPostI18n(PostI18n $l)
	{
		if ($this->collPostI18ns === null) {
			$this->initPostI18ns();
		}
		if (!in_array($l, $this->collPostI18ns, true)) { 			array_push($this->collPostI18ns, $l);
			$l->setPost($this);
		}
	}

	
	public function clearPostTags()
	{
		$this->collPostTags = null; 	}

	
	public function initPostTags()
	{
		$this->collPostTags = array();
	}

	
	public function getPostTags($criteria = null, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(PostPeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collPostTags === null) {
			if ($this->isNew()) {
			   $this->collPostTags = array();
			} else {

				$criteria->add(PostTagPeer::POST_ID, $this->id);

				PostTagPeer::addSelectColumns($criteria);
				$this->collPostTags = PostTagPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(PostTagPeer::POST_ID, $this->id);

				PostTagPeer::addSelectColumns($criteria);
				if (!isset($this->lastPostTagCriteria) || !$this->lastPostTagCriteria->equals($criteria)) {
					$this->collPostTags = PostTagPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastPostTagCriteria = $criteria;
		return $this->collPostTags;
	}

	
	public function countPostTags(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(PostPeer::DATABASE_NAME);
		} else {
			$criteria = clone $criteria;
		}

		if ($distinct) {
			$criteria->setDistinct();
		}

		$count = null;

		if ($this->collPostTags === null) {
			if ($this->isNew()) {
				$count = 0;
			} else {

				$criteria->add(PostTagPeer::POST_ID, $this->id);

				$count = PostTagPeer::doCount($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(PostTagPeer::POST_ID, $this->id);

				if (!isset($this->lastPostTagCriteria) || !$this->lastPostTagCriteria->equals($criteria)) {
					$count = PostTagPeer::doCount($criteria, $con);
				} else {
					$count = count($this->collPostTags);
				}
			} else {
				$count = count($this->collPostTags);
			}
		}
		$this->lastPostTagCriteria = $criteria;
		return $count;
	}

	
	public function addPostTag(PostTag $l)
	{
		if ($this->collPostTags === null) {
			$this->initPostTags();
		}
		if (!in_array($l, $this->collPostTags, true)) { 			array_push($this->collPostTags, $l);
			$l->setPost($this);
		}
	}


	
	public function getPostTagsJoinTag($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
	{
		if ($criteria === null) {
			$criteria = new Criteria(PostPeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collPostTags === null) {
			if ($this->isNew()) {
				$this->collPostTags = array();
			} else {

				$criteria->add(PostTagPeer::POST_ID, $this->id);

				$this->collPostTags = PostTagPeer::doSelectJoinTag($criteria, $con, $join_behavior);
			}
		} else {
									
			$criteria->add(PostTagPeer::POST_ID, $this->id);

			if (!isset($this->lastPostTagCriteria) || !$this->lastPostTagCriteria->equals($criteria)) {
				$this->collPostTags = PostTagPeer::doSelectJoinTag($criteria, $con, $join_behavior);
			}
		}
		$this->lastPostTagCriteria = $criteria;

		return $this->collPostTags;
	}

	
	public function clearComments()
	{
		$this->collComments = null; 	}

	
	public function initComments()
	{
		$this->collComments = array();
	}

	
	public function getComments($criteria = null, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(PostPeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collComments === null) {
			if ($this->isNew()) {
			   $this->collComments = array();
			} else {

				$criteria->add(CommentPeer::POST_ID, $this->id);

				CommentPeer::addSelectColumns($criteria);
				$this->collComments = CommentPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(CommentPeer::POST_ID, $this->id);

				CommentPeer::addSelectColumns($criteria);
				if (!isset($this->lastCommentCriteria) || !$this->lastCommentCriteria->equals($criteria)) {
					$this->collComments = CommentPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastCommentCriteria = $criteria;
		return $this->collComments;
	}

	
	public function countComments(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(PostPeer::DATABASE_NAME);
		} else {
			$criteria = clone $criteria;
		}

		if ($distinct) {
			$criteria->setDistinct();
		}

		$count = null;

		if ($this->collComments === null) {
			if ($this->isNew()) {
				$count = 0;
			} else {

				$criteria->add(CommentPeer::POST_ID, $this->id);

				$count = CommentPeer::doCount($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(CommentPeer::POST_ID, $this->id);

				if (!isset($this->lastCommentCriteria) || !$this->lastCommentCriteria->equals($criteria)) {
					$count = CommentPeer::doCount($criteria, $con);
				} else {
					$count = count($this->collComments);
				}
			} else {
				$count = count($this->collComments);
			}
		}
		$this->lastCommentCriteria = $criteria;
		return $count;
	}

	
	public function addComment(Comment $l)
	{
		if ($this->collComments === null) {
			$this->initComments();
		}
		if (!in_array($l, $this->collComments, true)) { 			array_push($this->collComments, $l);
			$l->setPost($this);
		}
	}


	
	public function getCommentsJoinUser($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
	{
		if ($criteria === null) {
			$criteria = new Criteria(PostPeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collComments === null) {
			if ($this->isNew()) {
				$this->collComments = array();
			} else {

				$criteria->add(CommentPeer::POST_ID, $this->id);

				$this->collComments = CommentPeer::doSelectJoinUser($criteria, $con, $join_behavior);
			}
		} else {
									
			$criteria->add(CommentPeer::POST_ID, $this->id);

			if (!isset($this->lastCommentCriteria) || !$this->lastCommentCriteria->equals($criteria)) {
				$this->collComments = CommentPeer::doSelectJoinUser($criteria, $con, $join_behavior);
			}
		}
		$this->lastCommentCriteria = $criteria;

		return $this->collComments;
	}

	
	public function clearAllReferences($deep = false)
	{
		if ($deep) {
			if ($this->collPostI18ns) {
				foreach ((array) $this->collPostI18ns as $o) {
					$o->clearAllReferences($deep);
				}
			}
			if ($this->collPostTags) {
				foreach ((array) $this->collPostTags as $o) {
					$o->clearAllReferences($deep);
				}
			}
			if ($this->collComments) {
				foreach ((array) $this->collComments as $o) {
					$o->clearAllReferences($deep);
				}
			}
		} 
		$this->collPostI18ns = null;
		$this->collPostTags = null;
		$this->collComments = null;
			$this->aUser = null;
	}


  
  public function getCulture()
  {
    return $this->culture;
  }

  
  public function setCulture($culture)
  {
    $this->culture = $culture;
  }

  public function getTitle($culture = null)
  {
    return $this->getCurrentPostI18n($culture)->getTitle();
  }

  public function setTitle($value, $culture = null)
  {
    $this->getCurrentPostI18n($culture)->setTitle($value);
  }

  public function getContent($culture = null)
  {
    return $this->getCurrentPostI18n($culture)->getContent();
  }

  public function setContent($value, $culture = null)
  {
    $this->getCurrentPostI18n($culture)->setContent($value);
  }

  protected $current_i18n = array();

  public function getCurrentPostI18n($culture = null)
  {
    if (is_null($culture))
    {
      $culture = is_null($this->culture) ? sfPropel::getDefaultCulture() : $this->culture;
    }

    if (!isset($this->current_i18n[$culture]))
    {
      $obj = PostI18nPeer::retrieveByPK($this->getId(), $culture);
      if ($obj)
      {
        $this->setPostI18nForCulture($obj, $culture);
      }
      else
      {
        $this->setPostI18nForCulture(new PostI18n(), $culture);
        $this->current_i18n[$culture]->setCulture($culture);
      }
    }

    return $this->current_i18n[$culture];
  }

  public function setPostI18nForCulture($object, $culture)
  {
    $this->current_i18n[$culture] = $object;
    $this->addPostI18n($object);
  }

} 